<template>
  <div class="video_item m_w m_h m_pr" v-if="item.username">

    <!-- 视频 -->
    <div class="video_box m_flex m_faic m_w m_h">
      <video ref="video" class="m_w" :src="ip+item.videoUrl"
      @click="onPlay" loop></video>
      <div v-show="isPaused" class="btn_box" @click="onPlay">
        <van-icon name="play-circle" size="60" class="btn"/>
      </div>
    </div>

    <!-- 右侧 toolbar -->
    <div class="m_flex m_fdc m_pa m_pr0 m_pb0 m_tac toolbar">
      <!-- 头像 -->
      <div class="m_flex m_fdc m_faic m_pr toolbar_item toolbar_item_avatar"
      @click="clickToolBar('avatar')">
        <img v-if="item.avatarUrl" :src="ip+item.avatarUrl" class="avatar m_br50p">
        <div v-else class="avatar m_br50p">{{item.username.slice(4,5)}}</div>
        <span class="m_fs16 m_br50p m_pa m_pb0">+</span>
      </div>
      <!-- 点赞 -->
      <div class="m_flex m_fdc toolbar_item" @click="clickToolBar('like')">
        <i class="iconfont icon-dianzan_kuai m_fs30" :class="liked?'liked':''"></i>
        <span class="m_fs12">{{item.likeCount}}</span>
      </div>
      <!-- 收藏 -->
      <div class="m_flex m_fdc toolbar_item" @click="clickToolBar('collect')">
        <i class="iconfont icon-shoucangxiao m_fs30" :class="collected?'collected':''"></i>
        <span class="m_fs12">{{item.collectCount}}</span>
      </div>
      <!-- 评论 -->
      <div class="m_flex m_fdc toolbar_item" @click="clickToolBar('comment')">
        <i class="iconfont icon-pinglun m_fs30"></i>
        <span class="m_fs12">{{item.commentCount}}</span>
      </div>
      <!-- 分享 -->
      <div class="m_flex m_fdc toolbar_item" @click="clickToolBar('share')">
        <!-- <i class="iconfont icon-fenxiang m_fs30"></i> -->
        <!-- <van-icon name="video" color="#fff" size="30"/> -->
        <van-icon name="share" color="#fff" size="36"/>
        <span class="m_fs12">分享</span>
      </div>
    </div>

    <!-- 底部 txtbar -->
    <div class="m_pa m_pb0 m_pl0 m_fs15 txtbar">
      <div class="m_fs16 m_fw author">@ {{item.nickname?item.nickname:item.username}}</div>
      <div class="van-multi-ellipsis--l3 content">{{item.intro}}</div>
    </div>

  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  props: {
    item: {type: Object, default: null},
    liked: {type: Boolean, default: false},
    collected: {type: Boolean, default: false},
    
  },
  data(){
    return {
      show: true,
      isPaused: true
    }
  },
  computed:{
    ...mapState(['ip'])
  },
  methods:{
    onPlay(){
      if(this.$refs.video.paused){
        this.$refs.video.play()
        this.isPaused = false
      }else{
        this.$refs.video.pause()
        this.isPaused = true
      }
    },
    // 播放
    play(){
      this.$refs.video.play()
    },
    // 暂停
    pause(){
      this.$refs.video.pause()
    },
    clickToolBar(option){
      this.$emit('clickToolBar',{
        item:this.item,
        option,
        liked: this.liked,
        collected: this.collected
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.video_item{
  .video_box{
    z-index: 0;
    position: relative;
    video{
      z-index: 0;
      max-height: 100%;
      object-fit: fill;
    }
    .btn_box{
      position: absolute;
      text-align: center;
      width: 100%;
      .btn{
        opacity: .6;
      }
    }
  }
  .toolbar{
    gap: 25px;
    padding-right: 12px;
    padding-bottom: 50px;
    .toolbar_item{
      gap: 5px;
      span{
        font-weight: bold;
      }
    }
    .toolbar_item_avatar{
      .avatar{
        width: 44px;
        height: 44px;
        line-height: 44px;
        margin-bottom: 8px;
        border: 2px solid #fff;
        background: #000;
        color: #fff;
      }
      span{
        bottom: 0px;
        width: 30px;
        height: 18px;
        border-radius: 9px;
        background: #008080;
      }
    }
    .liked{ color: deeppink;}
    .collected{ color: yellow;}
  }
  .txtbar{
    width: 78%;
    padding-left: 12px;
    padding-bottom: 10px;
    line-height: 24px;
    .content{
      opacity: .8;
    }
  }
}
</style>